/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import IO.ResourceCharacterLocation;
import java.awt.Image;
import java.io.File;
import java.util.ArrayList;
import javax.swing.ImageIcon;

/**
 *
 * @author avallejo
 */
public class Action {

    private int id = 0;
    private int dy = 0;
    private int dx = 0;
    private Image actorType;
    private String movementType = "";
    private String sound = "";
    public ArrayList<Image> images = new ArrayList<Image>();
    private String actorTypeString = "";
    private int indiceActualClosedLoop = 0;
    private int indiceActual = 0;
    
    public Action()
    {
    
    }
    
    public Action(int idDrag, int velocity, String type, String sound, Image actor) {
        this.id= idDrag;
        this.dx = this.dy = velocity;
        this.setMovementType(type);
        this.sound = sound;
        this.actorType = actor;
        images.add(actor);
        
    }
    
    public Action(int idDrag, int velocity, String type, String sound, Image actor,String actorTypeString) {
        this.id= idDrag;
        this.dx = this.dy = velocity;
        this.actorTypeString = actorTypeString;
        this.setMovementType(type);
        this.sound = sound;
        this.actorType = actor;
        images.add(actor);
        
    }
    
    
    public void fillDummyImageArray()
    {
        String charactersFolder = "/Carpeta Maestra/Personajes/P-Conejo/";
        String tempPath = "";
        String basePath = new File("").getAbsolutePath();
        String searchFolder = basePath + charactersFolder;
        String searchFile;
        
        for(int i=0; i<8; i++)
        {
         searchFile = searchFolder + (i+1) + ".png";
         images.add(new ImageIcon(searchFile).getImage());                
        
        }
        
    }
   public int getCurrentIndex()
   {
       return indiceActual;
   }
   
   public void setCurrentIndex(int newIndex)
   {
       indiceActual  = newIndex;
   }
   
   public void increaseIndex()
   {
       indiceActual = indiceActual + 1;
   }
   
   
   public void setImages(ArrayList<Image> newImgsArray)
   {
       images = newImgsArray;
   }
   
   public ArrayList<Image> getImgsArrayList()
   {
       return images;
   }
   
    
    public void setID(int newID)
    {
        this.id = newID;
    }
    
    public int getID()
    {
        return this.id;
    }
    
    public void setSoundPath(String newSoundPath)
    {
        this.sound = newSoundPath;
    }
    
    public String getSoundPath()
    {
        return sound;
    }
    
    //
    public void setactorType(Image actor)
    {
        this.actorType = actor;
    }
    
    public Image getactorType()
    {
        return this.actorType;
    }
    
    //X offset
    public void addHorizontalAction(int dx)
    {
        movementType = "Walk";
        this.dx = dx;
    }
    
    //Y offset
    public void addVerticalAction(int dy)
    {
       movementType = "Jump";
       this.dy = dy;
    }
    
    public int getdX()
    {
        return dx;
    }
    public void setDx(int dx)
    {
        this.dx = dx;
    }
    
    public int getdY()
    {
        return dy;
    }
    public void setDy(int dy)
    {
        this.dy = dy;
    }
    
    public String getMovementType()
    {
        return movementType;
    }
    
    public void setMovementType(String type)
    {
        this.movementType = type;
        
        //Stand, Walk, Jump, Jump
        String imgPrefix = "";
        
        switch (type) {
            case "Hablar":
                imgPrefix = "a";
                break;
            case "Saltar":
                imgPrefix = "s";
                break;
            case "Adelante":
                //no prefijo
                imgPrefix = "";
                break;
        }
        
        ResourceCharacterLocation rcl = new ResourceCharacterLocation();
        ArrayList<Image> imgTypes = rcl.loadImgArrayList(actorTypeString, type );
        
        
        
        
        //ResourceCharacterLocation rcl = new ResourceCharacterLocation();
        //rcl.loadImgArrayList(act, movementType)
    }
    
    public String getImagePath(){
        String name = "";
        switch(movementType){
            case "Adelante":
                name = "caminar";
            break;
            case "Atras":
                name = "retroceder";
            break;
            case "Saltar":
                name = "saltar";
            break;
            case "Hablar":
                name = "hablar";
            break;
            case "Voltear":
                name = "vuelta";
            break;
            default:
                name = "caminar";
            break;
        }
        return name;
    }
    
    
    public Image getSequence()
    {
        //Index is modular to continue looping through the images in the Images arralist
        int calculatedIndex = indiceActual % images.size();
        indiceActual++;
        return images.get(calculatedIndex);
    }
    
    public Image getSequenceClosedLoop()
    {
        //Index is modular to continue looping through the images in the Images arralist
        if (indiceActualClosedLoop<images.size())
        {            
            
            indiceActualClosedLoop++;
            return images.get(indiceActualClosedLoop-1);
        }                
                
        return null;
    }
    
    
    
    
    
}
    
